package com.ctshk.rpc.order.tour.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ctshk.rpc.order.tour.dto.SeriesOrderTouristNameListDTO;
import com.ctshk.rpc.order.tour.dto.SeriesOrderTouristRoomDTO;
import com.ctshk.rpc.order.tour.dto.SeriesOrderTouristRoomGroupDTO;
import com.ctshk.rpc.order.tour.entity.SeriesOrderTouristRoom;
import com.ctshk.rpc.order.tour.req.SeriesOrderTouristRoomReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * <p>
 * 系列团游客分房 Mapper 接口
 * </p>
 *
 * @author 张志朋
 * @since 2021-02-1
 */
public interface SeriesOrderTouristRoomMapper extends BaseMapper<SeriesOrderTouristRoom> {

    /**
     * 旅客分组列表
     */
    @Select("<script>"+"SELECT \n" +
            "t.id, gp.id groupId,gp.group_name groupName,t.lock_status lockStatus,t.noShow noShow, t.en_fullname enFullName,t.cn_fullname cnFullName,\n" +
            "t.people_type peopleType, t.tourist_type_name touristTypeName, t.pay_status payStatus, t.birthday birthday, t.gender gender, \n" +
            "t.nation nation, t.mobile mobile, t.email email, od.order_number orderNumber, od.order_source orderSource, t.create_id createId,\n" +
            "t.emergency_contact_name emergencyContactName, t.remark remark\n" +
            "FROM t_series_order_tourist_info t LEFT JOIN t_series_order od ON t.order_id = od.id LEFT JOIN t_series_order_tourist_room rm ON \n" +
            "t.room_id = rm.id LEFT JOIN t_series_order_tourist_group gp ON t.group_id = gp.id WHERE t.is_deleted = 0 AND od.is_deleted = 0 AND \n" +
            "t.schedule_id = #{roomReq.scheduleId}\n" +
            "<if test=\"roomReq.orderNumber != null and roomReq.orderNumber != ''\">and od.order_number LIKE CONCAT('%',#{roomReq.orderNumber},'%')</if>\n" +
            "<if test=\"roomReq.name != null and roomReq.name != ''\">and (t.cn_fullname LIKE CONCAT('%',#{roomReq.name},'%') or t.en_fullname LIKE CONCAT('%',#{roomReq.name},'%'))</if>\n" +
            "<if test=\"roomReq.touristTypeName != null and roomReq.touristTypeName != ''\">and t.tourist_type_name LIKE CONCAT('%',#{roomReq.touristTypeName},'%')</if>\n" +
            "<if test=\"roomReq.gender != null\">and t.gender = #{roomReq.gender}</if>\n" +
            "<if test=\"roomReq.groupName != null and roomReq.groupName != -1\">and gp.group_name = #{roomReq.groupName}</if>\n" +
            "<if test=\"roomReq.groupId != null\">and gp.id = #{roomReq.groupId}</if>\n" +
            "<if test=\"roomReq.lockStatus != null\">and t.lock_status = #{roomReq.lockStatus}</if>\n" +
            "<if test=\"roomReq.noShow != null\">and t.noShow = #{roomReq.noShow}</if>\n" +
            "<if test=\"roomReq.payStatus != null\">and t.pay_status = #{roomReq.payStatus}</if>\n" +
            "<if test=\"roomReq.orderSource != null\">and od.order_source = #{roomReq.orderSource}</if>\n" +
            "ORDER BY t.gmt_create DESC"+"</script>")
    IPage<SeriesOrderTouristRoomGroupDTO> queryList(Page<SeriesOrderTouristRoomGroupDTO> iPage, @Param("roomReq")SeriesOrderTouristRoomReq roomReq);


    /**
     * 旅客所有分房
     */
    @Select("<script>"+"SELECT \n" +
            "t.id id, rm.room_number roomNumber,t.lock_status lockStatus,t.noShow noShow, t.en_fullname enFullName,t.cn_fullname cnFullName,\n" +
            "t.people_type peopleType, t.tourist_type_name touristTypeName, t.pay_status payStatus, t.birthday birthday, t.gender gender, \n" +
            "t.nation nation, t.mobile mobile, t.email email, od.order_number orderNumber, od.order_source orderSource, t.create_id createId,\n" +
            "t.emergency_contact_name emergencyContactName, t.remark remark\n" +
            "FROM t_series_order_tourist_info t LEFT JOIN t_series_order od ON t.order_id = od.id LEFT JOIN t_series_order_tourist_room rm ON \n" +
            "t.room_id = rm.id LEFT JOIN t_series_order_tourist_group gp ON t.group_id = gp.id WHERE t.is_deleted = 0 AND od.is_deleted = 0 AND \n" +
            "t.schedule_id = #{roomReq.scheduleId}\n" +
            "ORDER BY t.gmt_create DESC"+"</script>")
    List<SeriesOrderTouristRoomDTO> roomList(@Param("roomReq")SeriesOrderTouristRoomReq roomReq);

    @Select("SELECT id id,max(room_number) roomNumber FROM t_series_order_tourist_room ")
    SeriesOrderTouristRoom queryMaxRoom();


}
